﻿CREATE PROCEDURE [dbo].[proc_Company_Range_Getlist]
	(
		@CompanyId int,
		@SText nvarchar(50),
		@startIndex int,
		@endIndex int
	)
AS
	--;WITH list As (Select ROW_NUMBER() OVER (ORDER BY R.CompanyId)AS Row,
	--R.Id,
	--R.TId,
	--R.UserName,
	--R.EName,
	--R.CompanyId,
	--ISNULL((Select CompanyName From Company Where Id=R.CompanyId),'...') As CompanyName,
	--R.UpName,
	--R.[UpDate],
	--R.IsAll
	--From Company_RangeUsers R 
	--Where (@CompanyId=0 Or CompanyId=@CompanyId) and (R.EName like '%'+ @SText +'%')
	--)
	
	
		;WITH list As (Select ROW_NUMBER() OVER (ORDER BY updatedate DESC)AS Row,
	
	R.UserName,
	R.Name,
	R.CompanyId,
	ISNULL((Select CompanyName From Company Where Id=R.CompanyId),'...') As CompanyName,
	ISNULL(updatedate,'1900-1-1') AS updatedate,
	cid
	From aspnet_Users R 
	Where (@CompanyId=0 Or CompanyId=@CompanyId) and (R.Name like '%'+ @SText +'%') AND cid!=''
	)
	
	
	Select *,(SELECT COUNT(1) FROM list ) AS datacount From list Where Row between @StartIndex and @EndIndex ORDER BY updatedate DESC
	RETURN
